﻿@inherits DemoWithResizableComponent

<div class="demo-description" id="DisabledDates">
    <h2><DemoNavLink Link="DateEdit#DisabledDates" />Date Edit - Disabled Dates<span class="demo-badge badge badge-success">New</span></h2>
    <p>In this demo module, several dates in the <a class="helplink" target="_blank" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxDateEdit-1">Date Edit's</a> calendar are grayed out (disabled) and cannot be selected. If a user clicks one of these dates, the Date Edit’s selected date does not change.</p>
    <p>To disable selection of specific dates based on custom logic, use the <a class="helplink" target="_blank" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxDateEdit-1.CustomDisabledDate">CustomDisabledDate</a> event.</p>
</div>

<div class="card demo-card demo-card-shadow">
    <div class="card-header">
        <DemoToolbar @bind-SelectedSize="SizeMode">
            <TitleTemplate>
                Date: <b>@DateTimeValue.ToString("dddd, dd MMMM yyyy")</b>
            </TitleTemplate>
        </DemoToolbar>
    </div>
    <div class="card-body mw-480">
        <DxDateEdit @bind-Date="@DateTimeValue" SizeMode="SizeMode" CustomDisabledDate="@OnCustomDisabledDate"></DxDateEdit>
    </div>
</div>

<div class="code-snippet card demo-card-wide">
    <CodeSnippetHeader></CodeSnippetHeader>
    <div class="card-footer text-muted ">
        <CodeSnippet_Editor_DateEdit_DisabledDates></CodeSnippet_Editor_DateEdit_DisabledDates>
    </div>
</div>

@code {
    DateTime DateTimeValue { get; set; } = DateTime.Today;

    void OnCustomDisabledDate(CalendarCustomDisabledDateEventArgs args) {
        args.IsDisabled = args.Date < DateTime.Today.AddDays(-20) || GetDisabledDates().Exists(d => DaysEqual(d, args.Date));
    }
    bool DaysEqual(DateTime date1, DateTime date2) {
        return (date1.Year == date2.Year && date1.DayOfYear == date2.DayOfYear);
    }
    List<DateTime> GetDisabledDates() {
        DateTime baseDate = DateTime.Today;
        return new List<DateTime>() { baseDate.AddDays(-9), baseDate.AddDays(-4), baseDate.AddDays(-3), baseDate.AddDays(3), baseDate.AddDays(5), baseDate.AddDays(6), baseDate.AddDays(15) };
    }
}
